<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="支付单号" prop="tradeSn">
      <el-input v-model="dataForm.tradeSn" placeholder="支付单号"></el-input>
    </el-form-item>
    <el-form-item label="" prop="userid">
      <el-input v-model="dataForm.userid" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="用户名" prop="username">
      <el-input v-model="dataForm.username" placeholder="用户名"></el-input>
    </el-form-item>
    <el-form-item label="" prop="contactname">
      <el-input v-model="dataForm.contactname" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="email">
      <el-input v-model="dataForm.email" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="telephone">
      <el-input v-model="dataForm.telephone" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="discount">
      <el-input v-model="dataForm.discount" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="存入金额" prop="money">
      <el-input v-model="dataForm.money" placeholder="存入金额"></el-input>
    </el-form-item>
    <el-form-item label="" prop="quantity">
      <el-input v-model="dataForm.quantity" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="支付时间" prop="addtime">
      <el-input v-model="dataForm.addtime" placeholder="支付时间"></el-input>
    </el-form-item>
    <el-form-item label="" prop="paytime">
      <el-input v-model="dataForm.paytime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="usernote">
      <el-input v-model="dataForm.usernote" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="payId">
      <el-input v-model="dataForm.payId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="业务方式" prop="payType">
      <el-input v-model="dataForm.payType" placeholder="业务方式"></el-input>
    </el-form-item>
    <el-form-item label="业务方式" prop="payment">
      <el-input v-model="dataForm.payment" placeholder="业务方式"></el-input>
    </el-form-item>
    <el-form-item label="" prop="type">
      <el-input v-model="dataForm.type" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="ip">
      <el-input v-model="dataForm.ip" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="付款状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="付款状态"></el-input>
    </el-form-item>
    <el-form-item label="" prop="adminnote">
      <el-input v-model="dataForm.adminnote" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="listid">
      <el-input v-model="dataForm.listid" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="bonus">
      <el-input v-model="dataForm.bonus" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="usd">
      <el-input v-model="dataForm.usd" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          tradeSn: '',
          userid: '',
          username: '',
          contactname: '',
          email: '',
          telephone: '',
          discount: '',
          money: '',
          quantity: '',
          addtime: '',
          paytime: '',
          usernote: '',
          payId: '',
          payType: '',
          payment: '',
          type: '',
          ip: '',
          status: '',
          adminnote: '',
          listid: '',
          bonus: '',
          usd: ''
        },
        dataRule: {
          tradeSn: [
            { required: true, message: '支付单号不能为空', trigger: 'blur' }
          ],
          userid: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          username: [
            { required: true, message: '用户名不能为空', trigger: 'blur' }
          ],
          contactname: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          email: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          telephone: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          discount: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          money: [
            { required: true, message: '存入金额不能为空', trigger: 'blur' }
          ],
          quantity: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          addtime: [
            { required: true, message: '支付时间不能为空', trigger: 'blur' }
          ],
          paytime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          usernote: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          payId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          payType: [
            { required: true, message: '业务方式不能为空', trigger: 'blur' }
          ],
          payment: [
            { required: true, message: '业务方式不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          ip: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '付款状态不能为空', trigger: 'blur' }
          ],
          adminnote: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          listid: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          bonus: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          usd: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/pay_account/v9payaccount/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.tradeSn = data.v9payaccount.tradeSn
                this.dataForm.userid = data.v9payaccount.userid
                this.dataForm.username = data.v9payaccount.username
                this.dataForm.contactname = data.v9payaccount.contactname
                this.dataForm.email = data.v9payaccount.email
                this.dataForm.telephone = data.v9payaccount.telephone
                this.dataForm.discount = data.v9payaccount.discount
                this.dataForm.money = data.v9payaccount.money
                this.dataForm.quantity = data.v9payaccount.quantity
                this.dataForm.addtime = data.v9payaccount.addtime
                this.dataForm.paytime = data.v9payaccount.paytime
                this.dataForm.usernote = data.v9payaccount.usernote
                this.dataForm.payId = data.v9payaccount.payId
                this.dataForm.payType = data.v9payaccount.payType
                this.dataForm.payment = data.v9payaccount.payment
                this.dataForm.type = data.v9payaccount.type
                this.dataForm.ip = data.v9payaccount.ip
                this.dataForm.status = data.v9payaccount.status
                this.dataForm.adminnote = data.v9payaccount.adminnote
                this.dataForm.listid = data.v9payaccount.listid
                this.dataForm.bonus = data.v9payaccount.bonus
                this.dataForm.usd = data.v9payaccount.usd
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/pay_account/v9payaccount/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'tradeSn': this.dataForm.tradeSn,
                'userid': this.dataForm.userid,
                'username': this.dataForm.username,
                'contactname': this.dataForm.contactname,
                'email': this.dataForm.email,
                'telephone': this.dataForm.telephone,
                'discount': this.dataForm.discount,
                'money': this.dataForm.money,
                'quantity': this.dataForm.quantity,
                'addtime': this.dataForm.addtime,
                'paytime': this.dataForm.paytime,
                'usernote': this.dataForm.usernote,
                'payId': this.dataForm.payId,
                'payType': this.dataForm.payType,
                'payment': this.dataForm.payment,
                'type': this.dataForm.type,
                'ip': this.dataForm.ip,
                'status': this.dataForm.status,
                'adminnote': this.dataForm.adminnote,
                'listid': this.dataForm.listid,
                'bonus': this.dataForm.bonus,
                'usd': this.dataForm.usd
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
 